
/***************************************************
> Copyright (C) 2024 ==QWZL== All rights reserved.
> File Name: income.c
> Author: xiaozhang
> Mail:1990614415@qq.com 
> Created Time: 2024年12月04日 星期三 09时40分28秒
***************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

typedef struct Material
{
	int code;
	char name[32];
	char specification[32];
	char model[32];
	char unit[8];
	int quantity;
	char mytime[16];
	struct Material *next;
}MAT;

int main(int argc,const char* argv[])
{
	FILE *fp = NULL;
	fp = fopen("./coming.csv","rb");//二进制读的方式打开文件
		if(fp == NULL)
		{
			perror("fopen");
			exit(1);
		}
		else
		{
			printf("open success");
		}
	MAT mat = {0};
	size_t rd = 0;
	rd = fread(&mat,sizeof(mat),1,fp);
		if(rd < 0)
		{
			perror("fread");
			exit(1);
		}
		else
		{
			printf("read success!\n");
		}
		//将文件读取出来
		char ch = 0;
		while(1)
		{
			ch = fgetc(fp);
			if(ch == EOF)
			{
				break;
			}
			printf("%c",ch);
		}
		//查询内容
	char key[6] = {0};
	printf("请输入需要查询的编码：");
	scanf("%s",key);
	MAT *temp = NULL;
	while(temp->next != NULL)
	{
		if(strcmp(temp->code,key) == 0)
		{
	printf("%d,%s,%s,%s,%s,%d,%s\n",temp->code,temp->name,temp->specification,temp->model,temp->unit,temp->quantity,temp->mytime);
		break;
		}
		temp = temp->next;
		if(temp == NULL)
		{
		printf("本仓库没有该材料，请确认唯一编码是否正确");
		}
	}
	fclose(fp);
		return 0;
}
